<template>
	<view class="coupon">
		<div class="tabbar">
			<div :class="tabbarIndex==1?'check':''" @click="bindEditTabbar(1)">可使用</div>
			<div :class="tabbarIndex==2?'check':''" @click="bindEditTabbar(2)">已失效</div>
		</div>
		<div class="list">
			<div :class="tabbarIndex==1?'item':'item invalid'" v-for="(item, index) in pageResult.list" :key="index">
				<div class="left">
					<p>
						<i>￥</i>
						<b>{{item.money}}</b>
					</p>
					<p>{{item.at_least > 0 ? "买满"+item.at_least+"元" : '无金额门槛'}}</p>
					<label>{{item.type_name}}</label>
				</div>
				<div class="right">
					<p>{{item.title}}</p>
					<p>至{{item.end_time}}</p>
					<p>{{item.remark}}</p>
					<label @click="jump('cart')" v-if="tabbarIndex==1">立即使用</label>
				</div>
			</div>
			<view v-if="pageResult.list.length == 0" class="nocontent">
				<image src="https://hdsq.aoorange.cn/attachment/xcx/icon/noItem.png" ></image>
				<!-- <text>暂无记录～</text> -->
			</view>
		</div>
	</view>
</template>

<script>
	import serve from '../../static/request.js';
	import storage from '../../static/appkey.js';
	import common from '../../static/jump.js';
	export default {
		data() {
			return {
				tabbarIndex:1,
				pageParam: {
					appkey: uni.getStorageSync('appkey'),
					'access-token': uni.getStorageSync('access-token'),
					status: 1,
					page: 0,
					pageSize: 10
				},
				pageResult: {
					list: [],
					isEmpty: false,
					isEnd: false
				}
			};
		},
		methods:{
			bindEditTabbar(i){
				if(this.tabbarIndex == i) {
					return ;
				}
				this.tabbarIndex=i;
				this.pageParam.status = i == 1 ? 1 : 0;
				this.pageParam.page=0;
				this.pageResult.list=[];
				this.getList();
			},
			getList() {
				var self = this;
				self.pageParam.page++
				serve
					.request({
						url: '/marketing/coupon-type/my-list',
						data: self.pageParam
					})
					.then(res => {
						if (res.data.all_list && res.data.all_list.length > 0) {
							self.pageResult.list=self.pageResult.list.concat(res.data.all_list);
						}
						self.pageResult.isEmpty = self.pageResult.list.length == 0;
						self.pageResult.isEnd = res.data.length == 0; 
					});
			},
			jump(jump_type, jump_link) {
				common.jump(jump_type, jump_link);
			}
		},
		onLoad() {
			this.pageParam.page=0;
			this.pageResult.list=[];
			this.getList(); 
		},
		onPullDownRefresh() {
			this.pageParam.page=0;
			this.pageResult.list=[];
			this.getList();
		},
		//触底加载
		onReachBottom() {
			if(this.pageResult.isEnd ||this.pageResult.isEmpty){
				return
			}
			this.getList()
		}
	};
</script>

<style lang="scss">
.coupon {
	.tabbar {
		width: 100%;
		height: 110rpx;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #ebebeb;

		div {
			flex: 1;
			color: #999999;
			font-size: 32rpx;
			margin-right: 68rpx;
			line-height: 110rpx;
			text-align: center;
			width: 50%;
		}
         
		.check {
			position: relative;
			color: #232323;
			font-weight: bold;
		}
		.check::after{
			content: "";
			position: absolute;
			left:45%;
			bottom: 0;
			width:30rpx;
			height:7rpx;
			background:rgba(255,188,0,1);
			border-radius:3rpx;
		}
	}

	.list {
		padding: 40rpx 30rpx;

		.item {
			width: 690rpx;
			height: 210rpx;
			background: url(https://hdsq.aoorange.cn/attachment/xcx/my/icon_coupon_back.png);
			background-size: 100% auto;
			display: flex;
			align-items: center;
			position: relative;
			margin-bottom: 40rpx;

			p,
			label {
				display: block;
			}

			.left {
				text-align: center;
				color: #fff;
				width: 226rpx;
				height: 210rpx;
				font-size: 20rpx;

				p {
					&:nth-child(1) {
						margin-top: 40rpx;
						b {
							font-size: 60rpx;
						}
					}
				}

				label {
					width: 100rpx;
					height: 30rpx;
					background: rgba(255, 255, 255, 0.2);
					border-radius: 15rpx;
					margin: 5rpx auto;
				}
			}

			.right {
				flex: 1;
				margin-left: 10rpx;
				p {
					color: #999999;
					&:nth-child(1) {
						color: #333333;
						font-size: 28rpx;
					}
					&:nth-child(2) {
						font-size: 24rpx;
						margin-top: 20rpx;
					}
					&:nth-child(3) {
						font-size: 20rpx;
						margin-top: 39rpx;
					}
				}

				.red {
					color: #ff5f60;
				}

				label {
					position: absolute;
					top: 50%;
					right: 30rpx;
					transform: translateY(-50%);
					width: 140rpx;
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;
					background: rgba(255, 99, 100, 1);
					border-radius: 24rpx;
					color: #fff;
					font-size: 24rpx;
				}
			}
		}

		.invalid{
			background: url(https://hdsq.aoorange.cn/attachment/xcx/my/icon_coupon_over_back.png);
			background-size: 100% auto;

			 .right{
				 label{
					 background: #DADADA;
				 }
			 }
		}
	}
	
	.nocontent{
		width: 100%;
		padding-top: 338rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		image{
			width:220rpx;
			height:220rpx;
		}
		text{
			font-size:28rpx;
			color:rgba(204,204,204,1);
		     margin-top: 30rpx;
		}
	}
}
</style>
